package cn.com.winning.ecare.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;
import android.widget.TextView;
import cn.com.winning.ecare.common.MyApplication;
import cn.com.winning.ecare.utils.DisplayUtil;

/**科室详情
 * @author Administrator
 *
 */
public class HospitalThree extends TabActivity
{
	private HospitalThree oThis = this;
	TabHost tabHost;
	private TabWidget mTabWidget;
	private String strKsId;
	private String strks;
	private String strkssx;
	private Intent mIntent;
	private ImageButton imb;
	private TextView tv;
	private ImageButton mainselected;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.hospital_three);
		MyApplication myApplication;
		myApplication = (MyApplication) getApplication();
		myApplication.addActivity(this);
		// 获取控件
		findView();
		iniTabHost();
	}

	private void findView()
	{
		imb = (ImageButton) findViewById(R.id.bmenuButton);
		tv = (TextView) findViewById(R.id.ksname);
		mIntent = getIntent();
		if (mIntent != null)
		{
			strKsId = mIntent.getStringExtra("strId");
			strks = mIntent.getStringExtra("strks");
			strkssx = mIntent.getStringExtra("strkssx");
		}
		tv.setText(strks);
		imb.setOnClickListener(new View.OnClickListener()
		{

			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				// Intent intent = new Intent(HospitalThree.this,
				// HospitalOne.class);
				// startActivity(intent);
				finish();

			}
		});

		tabHost = getTabHost();
		mTabWidget = (TabWidget) this.findViewById(android.R.id.tabs);
		mainselected = (ImageButton) this.findViewById(R.id.mainselected);

		mainselected.setOnClickListener(new OnClickListener()
		{

			@Override
			public void onClick(View view)
			{
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(oThis, Mainmean.class);
				startActivity(intent);
				oThis.finish();
			}
		});

	}

	private void iniTabHost()
	{

		Intent intent1 = new Intent();
		intent1.putExtra("strkssx", strkssx);
		intent1.setClass(this, Hospitalcontentks.class);

		Intent intent2 = new Intent();
		intent2.putExtra("strId", strKsId);
		intent2.setClass(this, Hospitalfour.class);

		// 新建一个tab并设置它的，Tag,标题，图标，内容
		tabHost.addTab(tabHost.newTabSpec("详情").setIndicator("详情").setContent(intent1));
		tabHost.addTab(tabHost.newTabSpec("医生").setIndicator("医生").setContent(intent2));
		tabHost.setCurrentTab(0);// 设置初始选中状态为第一个tab
		// 初始化TabHost
		for (int i = 0; i < mTabWidget.getChildCount(); i++)
		{
			RelativeLayout view = (RelativeLayout) mTabWidget.getChildAt(i);

			TextView text = (TextView) view.findViewById(android.R.id.title);
			text.setTextSize(18);
			RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) text.getLayoutParams();
			params.width = RelativeLayout.LayoutParams.MATCH_PARENT;
			params.height = RelativeLayout.LayoutParams.MATCH_PARENT;
			text.setLayoutParams(params);
			text.setGravity(Gravity.CENTER);
			view.setBackgroundColor(getResources().getColor(R.color.color_white));
			if (tabHost.getCurrentTab() == i)
			{
				text.setTextColor(getResources().getColor(R.color.listheadtext_color));

			}
			else
			{
				text.setTextColor(getResources().getColor(R.color.test_color_register));
			}
			int heightPx = DisplayUtil.dip2px(this, 50);
			mTabWidget.getChildAt(i).getLayoutParams().height = heightPx;
		}
		// TabHost切换
		tabHost.setOnTabChangedListener(new OnTabChangeListener()
		{

			public void onTabChanged(String tabId)
			{
				// TODO Auto-generated method stub
				for (int i = 0; i < mTabWidget.getChildCount(); i++)
				{
					View view = mTabWidget.getChildAt(i);
					TextView text = (TextView) view.findViewById(android.R.id.title);
					if (tabHost.getCurrentTab() == i)
					{
						text.setTextColor(getResources().getColor(R.color.listheadtext_color));
					}
					else
					{
						text.setTextColor(getResources().getColor(R.color.test_color_register));
					}
				}
			}

		});
	}

}
